<?php
namespace Partner\Controller;

use Utuo\BackgroundController;

class IndexController extends BackgroundController{

	public function _initialize(){
		$this->setControllerTitle('商家后台首页');
		$this->setActionTitle('home', '欢迎页面');
	}
	
	// 后台首页
	public function indexAction() {
		// 顶级菜单
		$aid = session(C("USER_AUTH_KEY"));
		$topMenu = M('partnerMenu a')->join('__PARTNER_MENU_MANAGER__ b on a.id=b.menu_id')->where('a.pid=0 AND a.is_deleted=0 AND b.aid=%d',$aid)->field("a.*")->order('a.sort')->select();
		// 快捷菜单
		$shortcutMenu = M('partnerMenu a')->join('__PARTNER_MENU_MANAGER__ b on a.id=b.menu_id')->where('a.pid=1 AND a.is_deleted=0 AND b.aid=%d',$aid)->field("a.*")->order('a.sort')->select();
		$this->assign('shortcutMenu', $shortcutMenu);
		$this->assign('topMenu', $topMenu);
		$this->assign('siteUrl', get_site_url($this->aid));
		$this->assign("sid", $this->aid);
		layout('layout');
		$this->display();
	}
	
	// 获取子菜单
	public function getSubMenuAction() {
		$pid = I('pid', 0, 'intval');
		$aid = session(C("USER_AUTH_KEY"))? session(C("USER_AUTH_KEY")):0;
		$subMenu = M('partnerMenu a')->join('__PARTNER_MENU_MANAGER__ b on a.id=b.menu_id')->where(array(
				'a.is_deleted' => 0,
				'a.pid' => $pid,
				'b.aid' => $aid, ))->order('a.sort')->select();
		$this->ajaxReturn($subMenu);
	}
	
	// 内容首页
	public function homeAction() {
		$this->display();
	}
}